package com.xys.springboot_easyui_a001.service.mybatis;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xys.springboot_easyui_a001.entity.User;
import com.xys.springboot_easyui_a001.mapper.UserMapper;
import com.xys.springboot_easyui_a001.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService implements IUserService {

    @Autowired
    private UserMapper userMapper;

    public List<User> findAll() {
        return userMapper.findAll();
    }

    public PageInfo<User> findPageInfo(Integer page, Integer rows, User user) {
        //1、设置分页信息，包括当前页数和每页显示的总计数
        PageHelper.startPage(page, rows);
        //2、执行查询
        List<User> list = userMapper.findByConditions(user);
        //3、获取分页查询后的数据
        PageInfo<User> pageInfo = new PageInfo<User>(list);
        return pageInfo;
    }

    public void insert(User user) {
        userMapper.insert(user);
    }

    public void update(User user) {
        userMapper.update(user);
    }

    public void deletes(Long[] ids) {
        userMapper.deletes(ids);
    }
}
